var express = require('express');
var router = express.Router();

  router.get('/shortmes', function (req, res, next) {
    req.dbs.Shortmes.find({},function (err,shortmeses) {
      res.send(shortmeses);
    })
  });

  router.post("/domain/Shortmes", function(req, res, next) {
    let {content} = req.body;
    if(content.length > 0 && content.length < 101){
      res.send({content});
    }else{
      res.send({error:{ title: "留言不得为空，且长度在100字以内。" }});
    }
  })

  router.get('/article', function (req, res) {
    req.dbs.Article.find({},function (err,articles) {
      // console.log("articles=",articles);
      res.send(articles);
    })
  });

  router.post("/domain/Article", function(req, res, next) {
      let {title, content} = req.body;
      if(title.length > 0 && title.length < 21){
        res.send({title, content});
      }else{
        res.send({error:{ title: "文章标题不得为空，且长度在20字以内。" }});
      }

  });

  router.get('/articledetail/:id', function (req, res, next) {
    req.dbs.Article.findOne({id:req.params.id},function (err,article) {
      res.send(article);
    })
  });
module.exports = router;
